package com.anolesoft.amljmes.delivery.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.anolesoft.amljmes.delivery.dto.MesPtmlBzzDto;
import com.anolesoft.amljmes.delivery.dto.MesCpjdjkDto;
import com.anolesoft.amljmes.delivery.service.MesCpjdjkService;
import com.anolesoft.common.core.web.domain.AjaxResult;
import com.anolesoft.yr.demo.PageResult;
import com.anolesoft.yr.util.Constants;
import com.anolesoft.yr.util.HttpStatus;

/**
 * 
 * @author 王佳明
 * @date 2022/5/6
 *
 */

@RestController
@CrossOrigin
@RequestMapping(value = "/cpjdjk")
public class MesCpjdjkController {

	@Autowired
	MesCpjdjkService service;
	
	@RequestMapping(value = "/querylist",method = RequestMethod.POST)
	public AjaxResult querylist(@RequestBody MesCpjdjkDto dto ) {
		String ddbh=dto.getDingdanbianhao();
		String ptdh=dto.getPeitaodanhao();
		String xh=dto.getXinghao();
		if(ddbh!=null) {
			dto.setDingdanbianhao(ddbh.toUpperCase().replace( " ",  ""));
		}
		if(ptdh!=null) {
			dto.setPeitaodanhao(ptdh.toUpperCase().replace( " ",  ""));
		}
		if(xh!=null) {
			dto.setXinghao(xh.toUpperCase().replace( " ",  ""));
		}

		List<MesCpjdjkDto> allList=service.queryList(dto);
		
		Integer endIndex = dto.getPageNumber()  * dto.getPageSize() > allList.size() ? allList.size() : dto.getPageNumber()  * dto.getPageSize();
		
		List<MesCpjdjkDto> list = allList.subList( (dto.getPageNumber() -1) *dto.getPageSize(), endIndex);
		
		PageResult pageResult = new PageResult(list, dto.getPageSize(), dto.getPageNumber(), allList.size());
		
		return new AjaxResult(HttpStatus.SUCCESS, Constants.QUERY_SUCCESS_MESSAGE,pageResult);
		
	}
}
